#include <cppunit/config/SourcePrefix.h>
#include "TestNode.h"
#include <string>

void TestNode::setUp() {
}

void TestNode::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestNode );

void TestNode::testGetNodeID(){
	Node procNode(new Procedure(0));
	procNode.setNodeID(0);
	Node assignNode(new Assign(), 1);
	assignNode.setNodeID(1);
	Node variableNode(new Variable(0), 1);
	variableNode.setNodeID(2);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("NodeID should be correct", 0, procNode.getNodeID());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("NodeID should be correct", 1, assignNode.getNodeID());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("NodeID should be correct", 2, variableNode.getNodeID());
}

void TestNode::testGetStmtNumber(){
	Node procNode(new Procedure(0));
	Node assignNode(new Assign(), 12);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("Node with default statement number", NOSTMTNUM, procNode.getStmtNumber());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Node with assigned statement number", 12, assignNode.getStmtNumber());
}

void TestNode::testGetDesignEntity(){
	Node plusNode(new Plus(), 1);
	Node variableNode(new Variable(0), 1);
	Node constantNode(new Constant(10), 1);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("Node with assigned design entity", VARIABLE, variableNode.getDesignEntity()->getType());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Node with assigned design entity", PLUS, plusNode.getDesignEntity()->getType());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Node with assigned design entity", CONSTANT, constantNode.getDesignEntity()->getType());
}

void TestNode::testAddGetChildNode(){
	Node plusNode(new Plus(), 1);
	Node variableNode(new Variable(0), 1);
	Node constantNode(new Constant(10), 1);
	plusNode.addChildNode(&variableNode);
	plusNode.addChildNode(&constantNode);

	vector<Node*> children = plusNode.getChildren();
	int size = children.size();
	Node* firstChild = children.at(0);
	Node* secondChild = children.at(1);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of children is correct", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("First child is plus node", &variableNode, firstChild);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Second child is constant node", &constantNode, secondChild);
}

void TestNode::testSetGetParent(){
	Node plusNode(new Plus(), 1);
	Node variableNode(new Variable(0), 1);
	variableNode.setParent(&plusNode);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("Parent node is plus node", &plusNode, variableNode.getParent());
}